home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 213_01 / xcr.c < prev    next >
Text File  |  1980-01-01  |  23KB  |  1,057 lines

  1. /* XCR.C    VERS:- 01.00  DATE:- 09/26/86  TIME:- 09:37:34 PM */
  2. /*
  3. %CC1 $1.C -O -X -E4000
  4. %CLINK $1 -S -E4000
  5. %DELETE $1.CRL 
  6. */
  7. /* 
  8. Description:
  9.  
  10. Cross-reference utility, from cug distribution disk.
  11.  
  12. Minor modification:
  13.     added check on characters of output per line (char_count),
  14.         to obtain correct pagination.
  15.  
  16. By J.A. Rupley, Tucson, Arizona
  17. Coded for BDS C compiler, version 1.50a
  18. */
  19. /* HEADER: CUG120.25;
  20.    TITLE: XC;
  21.    VERSION: 1.0;
  22.    DATE: 00/00/1982;
  23.    DESCRIPTION: "A cross-reference utility for C-programs.
  24.     It has the ability to handle nested include files to
  25.     a depth of 8.";
  26.    KEYWORDS: C programming,concordance generator;
  27.    SYSTEM: CP/M;
  28.    FILENAME: XC.C;
  29.    CRC: 3D48;
  30.    AUTHORS: Phillip N. Hisley;
  31.    COMPILERS: BDS C;
  32. */
  33. /***********************************************************/
  34. /*                               */
  35. /*    XC  -  A 'C' Concordance Utility                     */
  36. /*                               */
  37. /*    Version 1.0   January, 1982               */
  38. /*                               */
  39. /*    Copyright (c) 1982 by Philip N. Hisley               */
  40. /*                               */
  41. /*    Released for non-commercial distribution only        */
  42. /*                               */
  43. /*    Abstract:                           */
  44. /*                                   */
  45. /*    'XC' is a cross-reference utility for 'C' programs.  */
  46. /*    Its has the ability to handle nested include files   */
  47. /*    to a depth of 8 levels and properly processes nested */
  48. /*    comments as supported by BDS C. Option flags support */
  49. /*    the following features:                   */
  50. /*                               */
  51. /*    - Routing of list output to disk               */
  52. /*    - Cross-referencing of reserved words           */
  53. /*    - Processing of nested include files           */
  54. /*    - Generation of listing only               */
  55. /*                               */
  56. /*    Usage: xc <filename> <flag(s)>               */
  57. /*                               */
  58. /*    Flags: -i            = Enable file inclusion         */
  59. /*           -l               = Generate listing only         */
  60. /*           -r            = Cross-ref reserved words      */
  61. /*           -o <filename> = Write output to named file    */
  62. /*                               */
  63. /*                               */
  64. /*    -------------------------------------------------    */
  65. /*                               */
  66. /*    Compiliation Instructions - BDS C V1.42           */
  67. /*                               */
  68. /*    XC.C utilizes the dynamic storage allocation         */
  69. /*    scheme provided by BDS C .. this option must be      */
  70. /*    enabled per the instructions in BDSCIO.H           */
  71. /*                                   */
  72. /*    The -o and the -e options are used to maximize        */
  73. /*    the execution speed of XC.               */
  74. /*                               */
  75. /*    cc1 xc.c -o -e3560                       */
  76. /*    clink xc -s -e3560                          */
  77. /*                               */
  78. /*    Note: The location of the externals (-e3560)       */
  79. /*        is valid for version 1.0 of XC.C .. any       */
  80. /*          changes to XC.C which increase the size        */
  81. /*          of the generated code will require that        */
  82. /*          -e <xxxx> be resized .. also use of a       */
  83. /*          version of BDS C other than V1.42 may          */
  84. /*          alter the location of the external data        */
  85. /*        .. handle with care!               */
  86. /*                               */
  87. /*        Resizing Procedure:                   */
  88. /*                                   */
  89. /*          1. Compile/link XC with -o option:           */
  90. /*                                      */
  91. /*           cc1 XC.C -o                   */
  92. /*           clink XC -s                   */
  93. /*                                   */
  94. /*           The link map will indicate the address       */
  95. /*           at which external data starts .. in the       */
  96. /*           case of XC V1.0/BDS C V1.42 this becomes    */
  97. /*           3821h                       */
  98. /*                               */
  99. /*        2. Re-compile/link XC with the -o option       */
  100. /*             and the -e option using the external       */
  101. /*             data address obtained from step 1.       */
  102. /*                               */
  103. /*           cc1 XC.C -o -e3821               */
  104. /*           clink XC -s -e3821               */
  105. /*                                 */
  106. /*        3. Use of the -e option in step 2 will cause   */
  107. /*           the size of the generated code to become    */
  108. /*           smaller .. re-compile/link adjusting the    */
  109. /*             external data address to just above the     */
  110. /*             end of the code.                   */
  111. /*                               */
  112. /*             cc1 XC.C -o -e3560               */
  113. /*             clink XC -s -e3560               */
  114. /*                               */
  115. /*    -------------------------------------------------    */
  116. /*                               */
  117. /*    Please report bugs/fixes/enhancements to:            */
  118. /*                               */
  119. /*            Philip N. Hisley                   */
  120. /*          548H Jamestown Court               */
  121. /*          Edgewood, Maryland 21040               */
  122. /*          (301) 679-4606                   */
  123. /*                                   */
  124. /*                                                      */
  125. /***********************************************************/
  126.  
  127. #include "bdscio.h"
  128.  
  129. #define  LINELENGTH 63
  130. #define  MAX_REF    5        /* maximum refs per ref-block */
  131. #define  MAX_LEN    20        /* maximum identifier length  */
  132. #define  MAX_WRD   749        /* maximum number of identifiers */
  133. #define  MAX_ALPHA  53          /* maximum alpha chain heads */
  134. #define  REFS_PER_LINE  8    /* maximum refs per line */
  135. #define    LINES_PER_PAGE 60
  136. #define FF 0x0C            /* formfeed */
  137.  
  138. struct id_blk
  139. {
  140.     char id_name[MAX_LEN];
  141.     struct id_blk *alpha_lnk;
  142.     struct rf_blk *top_lnk;
  143.     struct rf_blk *lst_lnk;
  144. }
  145. oneid;
  146.  
  147. struct rf_blk
  148. {
  149.     int ref_item[MAX_REF];
  150.     int ref_cnt;
  151. }
  152. onerf;
  153.  
  154. struct id_blk *id_vector[MAX_WRD];
  155.  
  156. struct alpha_hdr
  157. {
  158.     struct id_blk *alpha_top;
  159.     struct id_blk *alpha_lst;
  160. }
  161. ;
  162.  
  163. struct alpha_hdr alpha_vector[MAX_ALPHA];
  164.  
  165. int char_count;
  166. int linum;        /* line number */
  167. int edtnum;        /* edit line number */
  168. int fil_cnt;        /* active file index */
  169. int wrd_cnt;        /* token count */
  170. int pagno;        /* page number */
  171. int id_cnt;        /* number of unique identifiers */
  172. int rhsh_cnt;        /* number of conflict hits */
  173. int filevl;        /* file level  */
  174. int paglin;        /* page line counter */
  175. int prt_ref;
  176. char act_fil[MAX_LEN];
  177. char lst_fil[MAX_LEN];
  178. char gbl_fil[MAX_LEN];
  179. char l_buffer[BUFSIZ];
  180. int i_flg, o_flg, r_flg, l_flg;
  181.  
  182. main(argc, argv)
  183. int argc;
  184. char **argv;
  185.  
  186. {
  187.     char *arg;
  188.  
  189.     if (argc < 2)
  190.         use_err();
  191.     i_flg = r_flg = o_flg = l_flg = FALSE;
  192.     strcpy(gbl_fil, *++argv);
  193.     --argc;
  194.     if (gbl_fil[0] == '-')
  195.         use_err();
  196.     while (--argc != 0)
  197.     {
  198.         if (*(arg = *++argv) == '-')
  199.         {
  200.             switch (*++arg)
  201.             {
  202.             case 'I' :
  203.                 i_flg++;
  204.                 break;
  205.             case 'R' :
  206.                 r_flg++;
  207.                 break;
  208.             case 'L' :
  209.                 l_flg++;
  210.                 break;
  211.             case 'O' :
  212.                 {
  213.                     o_flg++;
  214.                     if (--argc == 0)
  215.                         use_err();
  216.                     strcpy(lst_fil, *++argv);
  217.                     if (lst_fil[0] == '-')
  218.                         use_err();
  219.                     break;
  220.                 }
  221.             default :
  222.                 use_err();
  223.             }
  224.         }
  225.         else
  226.             use_err();
  227.     }
  228.  
  229.     if (o_flg)
  230.     {
  231.         if (fcreat(lst_fil, l_buffer) == ERROR)
  232.         {
  233.             printf("ERROR: Unable to create list file - %s\n", lst_fil);
  234.             exit(0);
  235.         }
  236.         printf("XC ... 'C' Concordance Utility  v1.0\n\n");
  237.     }
  238.  
  239.     _allocp = NULL;        /* initialize memory allocation pointer */
  240.     prt_ref = FALSE;
  241.     for (linum = 0; linum < MAX_WRD; linum++)
  242.     {
  243.         id_vector[linum] = NULL;
  244.     }
  245.     for (linum = 0; linum < MAX_ALPHA; linum++)
  246.     {
  247.         alpha_vector[linum].alpha_top =
  248.             alpha_vector[linum].alpha_lst = NULL;
  249.     }
  250.     fil_cnt = wrd_cnt = linum = 0;
  251.     char_count = 1;
  252.     filevl = paglin = pagno = edtnum = 0;
  253.     id_cnt = rhsh_cnt = 0;
  254.     proc_file(gbl_fil);
  255.     if (!l_flg)
  256.     {
  257.         prnt_tbl();
  258.         printf("\nAllowable Symbols: %d\n", MAX_WRD);
  259.         printf("Unique    Symbols: %d\n", id_cnt);
  260.     }
  261.     if (o_flg)
  262.     {
  263.         nl();
  264.         if (fprintf(l_buffer, "%c", CPMEOF) == ERROR)
  265.             lst_err();
  266.         fflush(l_buffer);
  267.         fclose(l_buffer);
  268.     }
  269. }
  270.  
  271. strcmp(s, t)
  272. char s[], t[];
  273. {
  274.     int i;
  275.     i = 0;
  276.     while (s[i] == t[i])
  277.         if (s[i++] == '\0')
  278.             return (0);
  279.     return (s[i] - t[i]);
  280. }
  281.  
  282. char *strcpy(s1, s2)
  283. char *s1, *s2;
  284. {
  285.     char *temp;
  286.     temp = s1;
  287.     while (*s1++ = *s2++)
  288.         ;
  289.     return (temp);
  290. }
  291.  
  292. lst_err()
  293.  
  294. {
  295.     printf("\nERROR: Write error on list output file - %s\n",
  296.     lst_fil);
  297.     exit(0);
  298. }
  299.  
  300. use_err()
  301.  
  302. {
  303.     printf("\nERROR: Invalid parameter specification\n\n");
  304.     printf("Usage: xc <filename> <flag(s)>\n\n");
  305.     printf("Flags: -i            = Enable file inclusion\n");
  306.     printf("       -l